package com.coustemview.qianfeng.huaqiangbeistore.model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mingma on 2016/8/29.
 */
public class Mainpage_Oversear_Bean {
  public static List<Mainpage_Oversear_handler> getinfo(String result){
      List<Mainpage_Oversear_handler>list=new ArrayList<>();
      try {
          JSONObject object=new JSONObject(result);
          JSONObject data = object.getJSONObject("data");
          JSONArray bCategoryVos = data.getJSONArray("bCategoryVos");
          for (int i = 0; i <bCategoryVos.length() ; i++) {
              Mainpage_Oversear_handler handler=new Mainpage_Oversear_handler();
              JSONObject jsonObject = bCategoryVos.getJSONObject(i);
                    if(i==0) {
                      handler.headtitle="平板/笔记本";
                    }
                handler.price = jsonObject.getString("price");
                handler.oldPrice=jsonObject.getString("oldPrice");
                handler.title=jsonObject.getString("title");
                handler.nation=jsonObject.getString("nation");
                handler.skuImage=jsonObject.getString("skuImage");
                handler.category=0;
                handler.skuId=jsonObject.getString("skuId");
              list.add(handler);
          }


          JSONArray sCategoryVos = data.getJSONArray("sCategoryVos");
          for (int i = 0; i <sCategoryVos.length() ; i++) {
             Mainpage_Oversear_handler handler=new Mainpage_Oversear_handler();
              JSONObject jsonObject = sCategoryVos.getJSONObject(i);
                  if(i==0) {
                     handler.headtitle="手机专区";
                  }
              handler.price = jsonObject.getString("price");
              handler.oldPrice=jsonObject.getString("oldPrice");
              handler.title=jsonObject.getString("title");
              handler.nation=jsonObject.getString("nation");
              handler.skuImage=jsonObject.getString("skuImage");
              handler.category=1;
              handler.skuId=jsonObject.getString("skuId");
              list.add(handler);
          }

          JSONArray pCategoryVos = data.getJSONArray("pCategoryVos");
          for (int i = 0; i <pCategoryVos.length() ; i++) {
             Mainpage_Oversear_handler handler=new Mainpage_Oversear_handler();
              JSONObject jsonObject = pCategoryVos.getJSONObject(i);
              if(i==0) {
                handler.headtitle="配件专区";
              }
              handler.price = jsonObject.getString("price");
              handler.oldPrice=jsonObject.getString("oldPrice");
              handler.title=jsonObject.getString("title");
              handler.nation=jsonObject.getString("nation");
              handler.skuImage=jsonObject.getString("skuImage");
              handler.category=2;
              handler.skuId=jsonObject.getString("skuId");
              list.add(handler);
          }
          return list;
      } catch (JSONException e) {
          e.printStackTrace();
      }
      return null;
  }

    public static Mainpage_Oversear_position getposition(String result){
        Mainpage_Oversear_position position=new Mainpage_Oversear_position();
        try {
            JSONObject object= new JSONObject(result);
            JSONObject data = object.getJSONObject("data");
            JSONArray bCategoryVos = data.getJSONArray("bCategoryVos");
            JSONArray sCategoryVos = data.getJSONArray("sCategoryVos");
            JSONArray pCategoryVos = data.getJSONArray("pCategoryVos");
            position.position1=bCategoryVos.length();
            position.position2=sCategoryVos.length();
            position.position3=pCategoryVos.length();
            return position;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
}
